package com.group9.handinhand.dao.model;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.apache.commons.lang.ArrayUtils;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import com.group9.handinhand.service.so.CommunityPostSO;

@Entity
@Table(name = "COMMUNITY_POST")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class CommunityPost extends Post {
	
	private static final long serialVersionUID = 1L;
	
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "COMMUNITY_ID", nullable = false)
	private Community community;
	
	public CommunityPostSO convertToServiceObject(String... ignoreProperties) {
		CommunityPostSO so = (CommunityPostSO) convert(new CommunityPostSO(), 
			(String[]) ArrayUtils.addAll(ignoreProperties, new String[]{"community","user"}));
		so.setUser(super.getUser().convertToServiceObject(new String[]{"socialUsers"}));
		so.setCommunity(community.convertToServiceObject(new String[]{"moderators", "posts", "events","requests","offers"}));
		return so;
	}
	
	public Community getCommunity() {
		return community;
	}

	public void setCommunity(Community community) {
		this.community = community;
	}

	@Override
	public String toString() {
		return "CommunityPost [community=" + community + "]";
	}
	
	

}
